from tkinter import Tk
from  tkinter import Label
from  tkinter import Button
import tkinter.messagebox
import keyboard_mouse_Listener
import keyboard_mouse_Actioner
import threading
import time


class MainFrom(object):
    def __init__(self):
        self.wind = Tk()
        print("main form init")
        self.init_window()


    def init_window(self):
        self.wind.title("鼠键双骄")
        self.wind.geometry('400x200')
        self.label1 = Label(self.wind, text="点击按钮开始录制，按下esc键停止录制", font=('Arial', 12))
        self.label1.pack()
        self.btn1 = Button(self.wind, text="开始录制", width=10, height=2, command=self.on_btn1_click)
        self.btn1.pack()

        #self.label2 = Label(self.wind, textvariable =self.lb2_text, font=('Arial', 12))
        self.label2 = Label(self.wind, text='点击[开始录制]3秒后开始',  font=('Arial', 12))
        self.label2.pack()

        self.btn2 = Button(self.wind, text="执行", width=10, height=2, command=self.on_btn2_click)
        self.btn2.pack()

        self.label3 = Label(self.wind, text="点击[执行]后可按esc退出执行", font=('Arial', 12))
        self.label3.pack()

        self.wind.mainloop()
        pass
    

    def on_btn1_click(self):
        UIUpdateCutDownExecute(3, self.label2).start()
        #keyboard_mouse_Listener.Listener().start()


    def on_btn2_click(self):
        keyboard_mouse_Actioner.Actioner().start()



# 倒计时监听，更新UI触发自定义线程对象
class UIUpdateCutDownExecute(threading.Thread):
    def __init__(self, cut_down_time, label):
        super().__init__()
        self.cut_down_time = cut_down_time
        self.label = label

    def run(self):
        while self.cut_down_time >= 0:
            self.label['text'] = str(self.cut_down_time)
            time.sleep(1)
            self.cut_down_time -=1
        
        keyboard_mouse_Listener.Listener().start()


if __name__ == '__main__':
    MainFrom()